package com.asia.algorithmcode.dynamicProgram;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @DESCRIPTION: 118、杨辉三角，dp
 * @USER: wanfu
 * @DATE: 2025/5/22 星期四 11:01
 */
public class Generate {


    public static void main(String[] args) {
        List<List<Integer>> generate = new Generate().generate(5);

        System.out.println();
    }


    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> resList = new ArrayList<>();
        resList.add(Arrays.asList(1));
        if (numRows == 1) {
            return resList;
        }
        for (int i = 2; i <= numRows; i++) {
            List<Integer> list = new ArrayList<>();
            for (int j = 0; j < i; j++) {
                if (j == 0 || j == i - 1) {
                    list.add(1);
                } else {
                    List<Integer> preList = resList.get(resList.size() - 1);
                    list.add(preList.get(j - 1) + preList.get(j));
                }
            }
            resList.add(list);
        }
        return resList;
    }

}
